/**
 * @(#)com.basic.collection.MapTest
 *
 * Copyright (c) 2014-2018 上海纬视瑞科技有限公司
 *
 * DESC:
 *
 */
package com.basic.collection;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

/**
 * @author fusf
 * @version 1.0  2017/3/14
 */
public class MapTest {

    public static void main(String[] args) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("aaa","bbb");
        map.put("cc","bbb");
        map.put("dd","bbb");
        map.put("gg","bbb");
       // map.put("aaa","bbb");
        map.put(null,null);

        //map遍历方法一
        System.out.println("Map遍历方法一");
        for(Map.Entry entry :map.entrySet()) {
            System.out.println("key="+entry.getKey()+"----value="+entry.getValue());
        }
        System.out.println("Map遍历方法二,效率高于上面方法10%,，而且代码干净");
        for(String key :map.keySet()) {
            System.out.println("Key = "+key);
        }

        for(Object value :map.values()) {
            System.out.println("Value= "+value);
        }

        System.out.println("Map遍历方法三");
        Iterator iterator = map.entrySet().iterator();
        while(iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            System.out.println("key="+entry.getKey()+"----value="+entry.getValue());
        }







        Map<String,Object>  map_table = new Hashtable<String, Object>();
        map_table.put("aaa","bbb");
        map_table.put("cc","bbb");
        map_table.put("dd","bbb");
        map_table.put("gg","bbb");
        // map.put("aaa","bbb");
        //map_table.put(null,null);
        //map遍历方法
        for(Map.Entry entry :map_table.entrySet()) {
            System.out.println("key="+entry.getKey()+"----value="+entry.getValue());
        }

    }
}
